package com.xgk.boot.module.core.enums.biz;

import cn.hutool.core.util.ArrayUtil;
import com.xgk.boot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 拦截状态枚举
 * 订单状态：0-无 1-申请拦截 2-拦截中 3-拦截失败 4-已拦截
 * @author dhb52
 */
@Getter
@AllArgsConstructor
public enum InterceptionStatusEnum implements ArrayValuable<Integer> {

    NONE(0, "NONE"),
    APPLY(1, "APPLY"),
    INTERCEPTING(2, "INTERCEPTING"),
    INTERCEPTION_FAILED(3, "INTERCEPTION_FAILED"),
    BLOCKED(4, "BLOCKED");

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(InterceptionStatusEnum::getValue).toArray(Integer[]::new);

    /**
     * 类型
     */
    private final Integer value;
    /**
     * 名称
     */
    private final String name;

    @Override
    public Integer[] array() {
        return ARRAYS;
    }

    public static InterceptionStatusEnum valueOf(Integer interval) {
        return ArrayUtil.firstMatch(item -> item.getValue().equals(interval), InterceptionStatusEnum.values());
    }

}